namespace SimpleWebServices.Models
{
    using System.Xml.Serialization;
    using SimpleWebServices.Data;

    [XmlRoot("address")]
    public class InternationalAddress : Record
    {
        public InternationalAddress()
        {
            this.Lines = new DataCollection();
        }

        [XmlAttribute("code")]
        public string Code
        {
            get;
            set;
        }

        [XmlElement("coordinates")]
        public Coordinates Coordinates
        {
            get;
            set;
        }

        [XmlElement("country")]
        public Link<Country> Country
        {
            get;
            set;
        }

        [XmlIgnore]
        public override string Entity
        {
            get
            {
                Entity value = new Entity();
                value.Append(this.Code);
                value.Append(this.Coordinates);
                value.Append(this.Country);
                value.Append(this.Key);
                value.Append(this.Lines);

                return value;
            }
        }

        [XmlAttribute("key")]
        public string Key
        {
            get;
            set;
        }

        [XmlElement("lines")]
        public DataCollection Lines
        {
            get;
            set;
        }

        public T To<T>()
            where T : InternationalAddress
        {
            return this.Serialize().CreateNavigator().OuterXml.Deserialize<T>();
        }
    }
}